﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using PloobsEngine.Publishers;
using PloobsEngine.Physics.XJigLib;
using PloobsEngine.SceneControl;


namespace PloobsEngine.Behaviors
{
    public class CharacterJumpBehavior : IBehavior
    {
        private IAction ac1;
        private IAction ac2;

        private ActionPublishInformation collideTrue = new ActionPublishInformation(IsCollidingAction.COLLIDING,null,null);
        private ActionPublishInformation collideFalse = new ActionPublishInformation(IsCollidingAction.NOT_COLLIDING, null,null);
        private ActionPublishInformation jumping = new ActionPublishInformation(ApplyImpulseAction.IMPULSE,null,null);


        public CharacterJumpBehavior(IObject obj)
        {
            ac1 = new IsCollidingAction(obj.PhysicObject as JigLibXObject);
            ac2 = new CharacterJumpAction(obj.PhysicObject as JigLibXObject);
            actionsList.Add(ac1);
            actionsList.Add(ac2);
            
        }
        private IList<IAction> actionsList = new List<IAction>();
        
        #region IBehavior Members

        public void PerformBehavior(String state, object data)
        {
            if (ac1.Action() == IsCollidingAction.COLLIDING)
            {
                Notify(collideTrue);
                ac2.Action();
                Notify(jumping);
            }
            else
            {
                Notify(collideFalse);
            }
        }

        public const String JUMPBEHAVIOR = "JUMP";
        

        #endregion

        private ISubject _sub = new ConcreteSubject();
        #region ISubject Members

        public int ObserverNumber()
        {
            return _sub.ObserverNumber();
        }

        public void Attach(IObserver obs)
        {
            _sub.Attach(obs);
        }

        public void Dettach(IObserver obs)
        {
            _sub.Dettach(obs);
        }

        public void DettachAll()
        {
            _sub.DettachAll();
        }

        public void Notify(object obj)
        {
            _sub.Notify(obj);
        }

        #endregion

        #region IBehavior Members


        public string BehaviorName
        {
            get { return NAME; }
        }

        public static readonly String NAME = "JUMP";
        
       

        public IList<IAction> Actions
        {
            get { return actionsList; }
        }

       
        public void Release()
        {
            
        }

        #endregion
    }
}

